package com.qianfeng.xinyihezi.xinyihezi.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.qianfeng.xinyihezi.xinyihezi.R;
import com.qianfeng.xinyihezi.xinyihezi.model.XinYiBean;

import java.util.List;

/**
 * 作者：王加威 on 2016/11/15 09:59
 */

public class XinYiBeanAdapter extends RecyclerView.Adapter {
    private Context mContext;
    private List<XinYiBean.DataBean.GoodsBean> mGoodsBeen;

    public XinYiBeanAdapter(Context context, List<XinYiBean.DataBean.GoodsBean> goodsBeen) {
        mContext = context;
        mGoodsBeen = goodsBeen;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.zhuiti_item,null));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder= (ViewHolder) holder;
        Glide.with(mContext).load(mGoodsBeen.get(position).image_url).into(viewHolder.mImageView);
        viewHolder.mTextView1.setText(mGoodsBeen.get(position).short_name);
        viewHolder.mTextView2.setText("￥"+mGoodsBeen.get(position).p_price);
        viewHolder.mTextView3.setText(mGoodsBeen.get(position).like_count);
    }

    @Override
    public int getItemCount() {
        return mGoodsBeen == null ? 0 : mGoodsBeen.size();
    }

    private static class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView mImageView;
        private TextView mTextView1, mTextView2, mTextView3;

        public ViewHolder(View itemView) {
            super(itemView);
            mImageView = (ImageView) itemView.findViewById(R.id.zhuti_item_iv);
            mTextView1 = (TextView) itemView.findViewById(R.id.zhuti_item_title);
            mTextView2 = (TextView) itemView.findViewById(R.id.zhuti_item_price);
            mTextView3 = (TextView) itemView.findViewById(R.id.zhuti_item_liike);
        }
    }
}
